package com.uzai.console.web.jd;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSort;
import com.uzai.console.annotation.SystemLogType;
import com.uzai.console.dto.dy.dytoken.DyTokenQuery;
import com.uzai.console.dto.jd.jdtoken.JdTokenIdDto;
import com.uzai.console.dto.jd.jdtoken.JdTokenInfoDto;
import com.uzai.console.dto.jd.jdtoken.JdTokenQuery;
import com.uzai.console.dto.locallive.tlbtoken.TlbTokenIdDto;
import com.uzai.console.dto.locallive.tlbtoken.TlbTokenInfoDto;
import com.uzai.console.dto.locallive.tlbtoken.TlbTokenQuery;
import com.uzai.console.enums.OperationTypeEnum;
import com.uzai.console.enums.SystemModelEnum;
import com.uzai.console.service.jd.JdTokenService;
import com.uzai.console.service.locallive.TlbTokenService;
import com.uzai.console.vo.dy.dytoken.DyTokenInfoVo;
import com.uzai.console.vo.jd.jdtoken.JdTokenInfoVo;
import com.uzai.console.vo.locallive.tlbtoken.TlbTokenInfoVo;
import com.uzai.console.web.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * 产品
 * @author liuqi
 * @date 2021年08月16日 15:11
 */
@Api(value = "京东联盟",tags = "京东|京东联盟")
@ApiSort(10)
@RestController
public class JdTokenController extends BaseController {
    private Logger logger = LoggerFactory.getLogger(JdTokenController.class);

    @Autowired
    private JdTokenService jdTokenService;
    @Autowired
    private TlbTokenService tlbTokenService;

    @ApiOperation(value = "分页查询京东联盟列表", notes = "分页查询京东联盟列表", response = JdTokenInfoVo.class)
    @ApiOperationSupport(order = 1)
    @PostMapping("/jdToken/findJdTokenList")
    public Object findJdTokenList(@RequestBody JdTokenQuery jdTokenQuery){
        return jdTokenService.findJdTokenList(jdTokenQuery);
    }

    @ApiOperation(value = "查询京东联盟详情", notes = "查询京东联盟详情", response = JdTokenInfoVo.class)
    @ApiOperationSupport(order = 2)
    @PostMapping("/jdToken/findJdTokenInfo")
    public Object findJdTokenInfo(@RequestBody JdTokenIdDto jdTokenIdDto){
        return jdTokenService.findJdTokenInfo(jdTokenIdDto);
    }

    @SystemLogType(model = SystemModelEnum.JdToken, type = OperationTypeEnum.ADD)
    @ApiOperation(value = "添加京东联盟", notes = "添加京东联盟")
    @ApiOperationSupport(order = 3)
    @PostMapping("/jdToken/addToken")
    public Object addJdToken(@RequestBody JdTokenInfoDto jdTokenInfoDto){
        jdTokenService.addJdToken(jdTokenInfoDto);
        return true;
    }

    @SystemLogType(model = SystemModelEnum.JdToken, type = OperationTypeEnum.UPDATE)
    @ApiOperation(value = "修改京东联盟", notes = "修改京东联盟")
    @ApiOperationSupport(order = 4)
    @PostMapping("/jdToken/updateToken")
    public Object updateJdToken(@RequestBody JdTokenInfoDto jdTokenInfoDto){
        jdTokenService.updateJdToken(jdTokenInfoDto);
        return true;
    }

    @SystemLogType(model = SystemModelEnum.JdToken, type = OperationTypeEnum.DELETE)
    @ApiOperation(value = "删除京东联盟", notes = "删除京东联盟")
    @ApiOperationSupport(order = 5)
    @PostMapping("/jdToken/deleteToken")
    public Object deleteToken(@RequestBody JdTokenIdDto jdTokenInfoDto){
        jdTokenService.deleteToken(jdTokenInfoDto);
        return true;
    }

    @ApiOperation(value = "分页查询推老板京东联盟列表", notes = "分页查询推老板京东联盟列表", response = TlbTokenInfoVo.class)
    @ApiOperationSupport(order = 7)
    @PostMapping("/jdToken/findTlbTokenList")
    public Object findTlbTokenList(@RequestBody TlbTokenQuery tlbTokenQuery){
        if(StringUtils.isBlank(tlbTokenQuery.getType())){
            tlbTokenQuery.setType("jd");
        }
        return tlbTokenService.findTlbTokenList(tlbTokenQuery);
    }

    @ApiOperation(value = "查询推老板京东联盟详情", notes = "查询推老板京东联盟详情", response = TlbTokenInfoVo.class)
    @PostMapping("/jdToken/findTlbTokenInfo")
    public Object findTlbToken(@RequestBody TlbTokenIdDto tlbTokenIdDto){
        return tlbTokenService.findTlbTokenInfo(tlbTokenIdDto);
    }

    @SystemLogType(model = SystemModelEnum.TlbToken, type = OperationTypeEnum.ADD)
    @ApiOperation(value = "添加推老板京东联盟账号", notes = "添加推老板京东联盟账号")
    @ApiOperationSupport(order = 8)
    @PostMapping("/jdToken/addTlbToken")
    public Object addTlbToken(@RequestBody TlbTokenInfoDto tlbTokenInfoDto){
        if(StringUtils.isBlank(tlbTokenInfoDto.getType())){
            tlbTokenInfoDto.setType("jd");
        }
        tlbTokenService.addTlbToken(tlbTokenInfoDto);
        return true;
    }

    @SystemLogType(model = SystemModelEnum.TlbToken, type = OperationTypeEnum.UPDATE)
    @ApiOperation(value = "修改推老板京东联盟账号", notes = "修改推老板京东联盟账号")
    @ApiOperationSupport(order = 9)
    @PostMapping("/jdToken/updateTlbToken")
    public Object updateTlbToken(@RequestBody TlbTokenInfoDto tlbTokenInfoDto){
        tlbTokenService.updateTlbToken(tlbTokenInfoDto);
        return true;
    }

    @SystemLogType(model = SystemModelEnum.TlbToken, type = OperationTypeEnum.DELETE)
    @ApiOperation(value = "删除推老板京东联盟账户", notes = "删除推老板京东联盟账户")
    @ApiOperationSupport(order = 10)
    @PostMapping("/jdToken/deleteTlbToken")
    public Object deleteTlbToken(@RequestBody TlbTokenIdDto tlbTokenIdDto){
        if(StringUtils.isBlank(tlbTokenIdDto.getType())){
            tlbTokenIdDto.setType("jd");
        }
        tlbTokenService.deleteTlbToken(tlbTokenIdDto);
        return true;
    }

    @ApiOperation(value = "查询所有共享推老板京东联盟列表", notes = "查询所有共享推老板京东联盟列表", response = TlbTokenInfoVo.class)
    @ApiOperationSupport(order = 12)
    @PostMapping("/jdToken/findTlbJdTokenListSelect")
    public Object findTlbJdTokenListSelect(@RequestBody TlbTokenQuery tlbTokenQuery){
        if(StringUtils.isBlank(tlbTokenQuery.getType())){
            tlbTokenQuery.setType("jd");
        }
        return tlbTokenService.findTlbTokenListSelect(tlbTokenQuery);
    }
}
